package com.example.bloodbankapplication;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;

import com.example.bloodbankapplication.fragment.DonorRegistrationFragment;
import com.example.bloodbankapplication.fragment.DonorSearchFragment;
import com.example.bloodbankapplication.fragment.ListOfDonors;
import com.example.bloodbankapplication.fragment.RecentviewedDonorsFragment;
import com.example.bloodbankapplication.fragment.SuggestFriendFragment;
import com.example.bloodbankapplication.mailsender.UnCaughtException;

public class DashBoardActivity extends BaseActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_dash_board);
		Thread.setDefaultUncaughtExceptionHandler(new UnCaughtException(this));
		ActionBar actionbar = getActionBar();
		actionbar.setTitle("BloodBank");
		actionbar.setIcon(R.drawable.ic_launcher);   
		actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

		ActionBar.Tab tab1 = actionbar.newTab().setText("Registration");
		ActionBar.Tab tab2 = actionbar.newTab().setText("Donors");
		ActionBar.Tab tab3 = actionbar.newTab().setText("Search Donor");
		ActionBar.Tab tab4 = actionbar.newTab().setText("Viewed Donor");
		ActionBar.Tab tab5 = actionbar.newTab().setText("Suggest Friend");
		
		

		DonorRegistrationFragment donorRegistration = new DonorRegistrationFragment();
		ListOfDonors donorsList = new ListOfDonors();
		DonorSearchFragment searchDonor = new  DonorSearchFragment();
		RecentviewedDonorsFragment viewedDonor = new RecentviewedDonorsFragment();
		SuggestFriendFragment suggestFr = new SuggestFriendFragment();
		
		tab1.setTabListener(new MyTabListener(donorRegistration));
		tab2.setTabListener(new MyTabListener(donorsList));
		tab3.setTabListener(new MyTabListener(searchDonor));
		tab4.setTabListener(new MyTabListener(viewedDonor));
		tab5.setTabListener(new MyTabListener(suggestFr));

		actionbar.addTab(tab1);
		actionbar.addTab(tab2);
		actionbar.addTab(tab3);
		actionbar.addTab(tab4);
		actionbar.addTab(tab5);
		
		

	}

	class MyTabListener  implements TabListener{

		private Fragment myFragment;

		public MyTabListener(Fragment fragment) {


			this.myFragment = fragment;
		}

		@Override
		public void onTabReselected(Tab arg0, FragmentTransaction arg1) {

		}

		@Override
		public void onTabSelected(Tab arg0, FragmentTransaction ft) {

			ft.replace(R.id.fragment, myFragment);


		}

		@Override
		public void onTabUnselected(Tab arg0, FragmentTransaction fm) {
			fm.remove(myFragment);
		}

	}

/*	@Override
	public void getData(String type, String id) {
		
		DonorRegistrationFragment fragment = (DonorRegistrationFragment) getFragmentManager().findFragmentById(R.id.fragment);
		fragment.getVaues(type, id);
	}*/



}
